﻿ using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameLevelItem : MonoBehaviour
{
    public int levelId;
    public bool hideBackButton;
    public bool hideReplayButton;
    public bool hideLevelId;
    // Start is called before the first frame update
    void Start()
    {  

    }

    // Update is called once per frame
    void Update()
    {

    }

    public void TriggerResult(bool result)
    {
        if (GameCtrl.Instance.curGameState == GameState.Menu)
            return;
        GameCtrl.Instance.ChangeGameState(GameState.Menu);
        if (result)
        {
            //UmengSDK.Instance.FinishLevel(levelId.ToString());

            SoundManager.Instance.PlayAudio(SoundType.LevelComplete.ToString(), false);
            Invoke("NextLevel", 1);
            GameCtrl.Instance.UpdateLevelState(levelId, UConst.Level_State_Finish);
        }
        else
        {
            //UmengSDK.Instance.FailLevel(levelId.ToString());

            SoundManager.Instance.PlayAudio(SoundType.Error.ToString(), false);
            Invoke("Replay", 0.5f);
        }

        SDKManagerV2.Instance.LoadInterAd();
        SDKManagerV2.Instance.LoadRewardVideo();
    }

    private void NextLevel()
    {
        GameCtrl.Instance.playPanel.NextLevel();
    }

    private void Replay()
    {
        GameCtrl.Instance.playPanel.Replay();
    }

    public void Skip()
    {
        Invoke("NextLevel", 1);
        GameCtrl.Instance.UpdateLevelState(levelId, UConst.Level_State_Skip);
    }
}

